package org.smog.core.config.security.hander;

import org.smog.core.exception.UnauthorizedException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未认证处理
 *
 * @Description: Created by IntelliJ IDEA.
 * @project_name: smogTemp
 * @time: 2020-05-14 11:10
 * @email: 17685306043@163.com
 * @author: huangZhongYao
 */
@Component
public class JwtAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException {
        UnauthorizedException unauthorized = new UnauthorizedException("Unauthorized");
        httpServletResponse.sendError(unauthorized.getCode(), unauthorized.getMessage());
    }
}
